package com.woniu.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.platform.entity.PlatformAuditRecord;
import com.woniu.platform.mapper.PlatformAuditRecordMapper;
import com.woniu.platform.service.PlatformAuditRecordService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PlatformAuditRecordServiceImpl implements PlatformAuditRecordService {
    @Autowired(required = false)
    private PlatformAuditRecordMapper auditRecordMapper;

    @Override
    public HttpResult insertAuditRecord(PlatformAuditRecord platformAuditRecord) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        platformAuditRecord.setAuditTime(dateFormat.format(new Date()));
        int re = auditRecordMapper.insert(platformAuditRecord);
        if (re > 0) {
            return new HttpResult().ok();
        }else{
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult queryAuditRecord(RequestResult<PlatformAuditRecord> requestResult) {
        PageHelper.startPage(requestResult.getPageNum(), requestResult.getPageSize());
        List<PlatformAuditRecord> list = auditRecordMapper.queryAuditRecord(requestResult.getData().getFinance().getEnterpriseName(),
                                                                                                    requestResult.getData().getAuditResult());
        PageInfo pageInfo = new PageInfo(list);
        return new HttpResult().ok(pageInfo);
    }
}
